const express = require("express")
const router = express.Router()
const handlers = require("./handler/subject")
const multer = require('multer')
const path = require('path')

// 创建文件上传的处理器
const upload = multer({
  dest: path.join(__dirname, '../public/upload/excel'),
})
// 创建文件上传的处理器
const upload1 = multer({
  dest: path.join(__dirname, '../public/upload/course'),
})

// 课程分类列表
router.get("/vod/subject/getChildSubject/:id", handlers.getSubjectList)

// 课程导出为excel
router.get("/admin/vod/subject/exportData", handlers.exportSubject)

// 课程导入
router.post("/admin/vod/subject/importData", upload.single('file'), handlers.importSubject)

// 根据id获取课程信息
router.get("/vod/course/get/:id", handlers.getCourseById)

// 更新
router.post("/vod/course/update", handlers.updateCourse)

// 获取章节
router.get("/vod/chapter/getNestedTreeList/:id", handlers.getCourseChapter)

// 获取章节by id
router.get("/vod/chapter/get/:id", handlers.getCourseChapterById)

// 更新章节
router.post("/vod/chapter/update", handlers.updateChapter)

// 添加章节
router.post("/vod/chapter/save", handlers.addChapter)

// 保存课程
router.post("/vod/course/save", handlers.saveCourse)

// 删除章节
router.delete("/vod/chapter/remove/:id", handlers.deleteChapter)

// 课程封面上传
router.post("/admin/vod/file/course/upload", upload1.single('file'), handlers.uploadCourseImg)

// 获取发布课程的信息
router.get("/vod/course/getCoursePublishVo/:id", handlers.getPublishCourse)

// 课程列表
router.get("/vod/course/getList/:page?/:pageSize?", handlers.getCourseList)

// 发布课程
router.put('vod/course/publishCourse/:id', handlers.publishCourse)

// 全部课程列表
router.get("/vod/course/findAll", handlers.getAllCourseList)

module.exports = router
